package com.huobao.shangjia_version.activitys;

import java.util.List;
import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.adapters.Adapter_ZijinManager;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.entity.ZijinManager;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class Act_Zijin_Manager extends HuobaoBaseActivity implements OnScrollListener, OnClickListener {

	@ViewInject(R.id.listview)
	private ListView listview;
	private View HeadView;
	private View FootView;
	private TextView tv_search;
	private TextView tv_foot_msg;
	private Adapter_ZijinManager adapter;
	private int m_CurrentPage = 1;
	private boolean isLoading = true;

	// 冻结金额
		String epay_dj;
		// 可用金额
		String epay_money;

		@Override
		protected int getContentView() {
			return R.layout.layout_zijin_manager;
		}

		@Override
		protected String getTitleText() {
			return getString(R.string.title_11);
		}

	@Override
	protected void init() {
		epay_dj = getIntent().getStringExtra("epay_dj");
		epay_money = getIntent().getStringExtra("epay_money");
		HeadView = LayoutInflater.from(context).inflate(R.layout.item_zijin_manager_head, null);
		TextView tv_yue = (TextView) HeadView.findViewById(R.id.tv_yue);
		TextView tv_dongjie = (TextView) HeadView.findViewById(R.id.tv_dongjie);
		Button btn_chongzhi = (Button) HeadView.findViewById(R.id.btn_chongzhi);
		Button btn_tixian = (Button) HeadView.findViewById(R.id.btn_tixian);
		btn_chongzhi.setOnClickListener(this);
		btn_tixian.setOnClickListener(this);
		tv_yue.setText(epay_money);
		tv_dongjie.setText(epay_dj);
		FootView = LayoutInflater.from(context).inflate(R.layout.item_footview, null);
		tv_search = (TextView) HeadView.findViewById(R.id.edt_search);
		tv_foot_msg = (TextView) FootView.findViewById(R.id.tv_message);
		listview.addHeaderView(HeadView);
		listview.addFooterView(FootView);
		adapter = new Adapter_ZijinManager(context);
		listview.setAdapter(adapter);
		listview.setOnScrollListener(this);
		getList(true);
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {

	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
		if (isLoading)
			return;
		if ((firstVisibleItem + visibleItemCount) == totalItemCount) {
			m_CurrentPage++;
			getList(false);
		}
	}

	private void getList(boolean isShowLoading) {
		isLoading = true;
		Map<String, String> map = HttpUtil.getParams("app", "shopmember", "act", "logall", "page", "" + m_CurrentPage);
		Http.getInstant().sendRequest(context, isShowLoading, map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				List<ZijinManager> list = JSON.parseArray(jsonObject.getString("retval"), ZijinManager.class);
				if (list == null || list.size() == 0) {
					tv_foot_msg.setText("加载完成");
					isLoading = true;
					return;
				}
				adapter.addAll(list);
				isLoading = false;
			}

			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub

			}
		});

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_chongzhi:
			break;
		case R.id.btn_tixian:
			break;
		}
	}

}
